package com.neuedu.funlifebbs.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neuedu.funlifebbs.bean.Categorys;
import com.neuedu.funlifebbs.dao.CategorysMapper;
import com.neuedu.funlifebbs.query.CategorysQuery;
import com.neuedu.funlifebbs.service.CategorysService;

/**
 * 
 * @author myh
 * @version 2019年8月19日下午1:44:35
 *
 */
@Service
public class CategorysServiceImpl implements CategorysService {

	@Autowired
	CategorysMapper categorysMapper;

	@Override
	public Categorys findById(int id) {
		return categorysMapper.findById(id);
	}

	@Override
	public PageInfo<Categorys> query(CategorysQuery categorysQuery) {
		// 要不要分页
		if (categorysQuery.isPaging()) {
			// 使用分页插件
			PageHelper.startPage(categorysQuery.getPageNum(),
					categorysQuery.getLimit());
			Page<Categorys> pageInfo = (Page<Categorys>) categorysMapper
					.query(categorysQuery);
			return pageInfo.toPageInfo();
		} else {
			PageInfo<Categorys> pageInfo = new PageInfo<Categorys>(
					categorysMapper.query(categorysQuery));
			return pageInfo;
		}
	}

	@Override
	public int add(Categorys categorys) {
		return categorysMapper.add(categorys);
	}

	@Override
	public int deleteById(int id) {
		return categorysMapper.deleteById(id);
	}

	@Override
	public int update(Categorys categorys) {
		return categorysMapper.update(categorys);
	}

	@Override
	public List<Categorys> findAll() {
		return categorysMapper.findAll();
	}

}
